<?php
// load the theme options
$options = get_option( 'complete_theme_settings' );

// general includes
include('functions/theme-admin.php');
include('functions/pagination.php');
include('functions/better-excerpts.php');
include('functions/better-comments.php');
include('functions/shortcodes/shortcodes.php');
include('functions/shortcodes/shortcode-pop-up.php');

// widgets
include('functions/widgets/recent-posts.php');
include('functions/widgets/recent-portfolio.php');
include('functions/widgets/recent-comments.php');
include('functions/widgets/flickr.php');

// metaboxes
include('functions/metaboxes/pricing-meta.php');
include('functions/metaboxes/slides-meta.php');
include('functions/metaboxes/portfolio-meta.php');
include('functions/metaboxes/highlights-meta.php');

// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator'); // remove WordPress Version For Security Reasons
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );

// get scripts
add_action('wp_enqueue_scripts','complete_scripts_function');
function complete_scripts_function() {
global $options; //get options outside of function
	
// use Google JS script
   wp_deregister_script('jquery'); 
   wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false, '1.4.2'); 
   wp_enqueue_script('jquery');
   
// include all JS to the WP hook
	wp_enqueue_script('sliding_effect', get_stylesheet_directory_uri() . '/js/sliding_effect.js', array('jquery'), '1.0', false);
	wp_enqueue_script('scrollTo', get_stylesheet_directory_uri() . '/js/jquery.scrollTo-min.js', array('jquery'), '1.4.2', false);
	wp_enqueue_script('superfish', get_stylesheet_directory_uri() . '/js/superfish.js', array('jquery'), '1.4.8', false);
	wp_enqueue_script('supersubs', get_stylesheet_directory_uri() . '/js/supersubs.js', array('jquery'), '0.2', false);
	wp_enqueue_script('main', get_stylesheet_directory_uri() . '/js/main.js', array('jquery'), '1.0', false);
	
	if(is_front_page()) :
	wp_enqueue_script('nivoSlider', get_stylesheet_directory_uri() . '/js/jquery.nivo.slider.pack.js', array('jquery'), '2.5.1', false);
	wp_enqueue_script('bxSlider', get_stylesheet_directory_uri() . '/js/jquery.bxSlider.min.js', array('jquery'), '3.0', false);
	endif;
	
	if (is_page_template( 'template-portfolio.php' )) : 
	wp_enqueue_script('prettyPhoto', get_stylesheet_directory_uri() . '/js/jquery.prettyPhoto.js', array('jquery'), '3.1.1', false);
	wp_enqueue_script('equalHeights', get_stylesheet_directory_uri() . '/js/equalHeights.js', array('jquery'), '1.0', false);
		if ($options['disable_portfolio_filter'] != true) {
			wp_enqueue_script('filterable', get_stylesheet_directory_uri() . '/js/filterable.js', array('jquery'), '1.0', false);
		}
	endif;
	
	if (is_tax()) : 
	wp_enqueue_script('prettyPhoto', get_stylesheet_directory_uri() . '/js/jquery.prettyPhoto.js', array('jquery'), '3.1.1', false);
	wp_enqueue_script('equalHeights', get_stylesheet_directory_uri() . '/js/equalHeights.js', array('jquery'), '1.0', false);
	endif;
	
	if (is_single()) : 
	wp_enqueue_script('localscroll', get_stylesheet_directory_uri() . '/js/jquery.localscroll-1.2.7-min.js', array('jquery'), '1.2.7', false);
	endif;
	
	if (is_page_template( 'template-pricing.php' )) :
	wp_enqueue_script('equalHeights', get_stylesheet_directory_uri() . '/js/equalHeights.js', array('jquery'), '1.0', false);
	endif;

	if (is_page_template( 'template-services.php' )):
	wp_enqueue_script('tabs', get_stylesheet_directory_uri() . '/js/tabs.js', array('jquery'), '1.0', false);
	endif;
}

// featured image sizes
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'full-size',  9999, 9999, false ); // full size image
add_image_size( 'home-slide',  920, 320, true ); // slider image
add_image_size( 'home-highlights',  270, 140, true ); // homepage highlights image
add_image_size( 'home-blog',  205, 160, true ); // homepage blog image
add_image_size( 'testimonials',  80, 80, true ); // testimonials image
add_image_size( 'related-posts',  50, 50, true ); // single posts related
add_image_size( 'related-portfolio-posts',  190, 118, true ); // portfolio related
add_image_size( 'related-portfolio-posts',  190, 118, true ); // portfolio related
add_image_size( 'portfolio-homepage',  210, 160, true ); // portfolio homepage scrollbar image
add_image_size( 'portfolio-one-column',  440, 250, true ); // portfolio column image
add_image_size( 'portfolio-two-column',  440, 250, true ); // portfolio column image
add_image_size( 'portfolio-three-column',  290, 185, true ); // portfolio 3 column image
add_image_size( 'portfolio-four-column',  210, 130, true ); // portfolio 4 column image
add_image_size( 'blog',  260, 210, true ); // blog image
add_image_size( 'recent-post-widget',  50, 50, true ); // thumbnail for recent posts widget
add_image_size( 'recent-portfolio-widget',  240, 150, true ); // thumbnail for recent portfolio widget
}

// get permalink by title
function get_permalink_by_name($page_name) {
        global $post;
        global $wpdb;
        $pageid_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '" . $page_name . "' LIMIT 0, 1");
        return get_permalink($pageid_name);
}

// replace general excerpt length
function complete_new_excerpt_more($more) {
       global $post;
	return '...';
}
add_filter('excerpt_more', 'complete_new_excerpt_more');


// activate post-image function
if ( function_exists( 'add_theme_support' ) )
add_theme_support( 'post-thumbnails' );

// enable custom background support
add_custom_background();

// register navigation menus
register_nav_menus(
	array(
	'main nav'=>__('Main Nav'),
	)
);

// menu fallback
function default_menu() {
	require_once (TEMPLATEPATH . '/includes/default-menu.php');
}

// register sidebars
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Blog Sidebar',
'description' => 'Widgets in this area will be shown in the sidebar.',
'before_widget' => '<div class="sidebar-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Pages Sidebar',
'description' => 'Widgets in this area will be shown in the sidebar.',
'before_widget' => '<div class="sidebar-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'name' => 'Portfolio Sidebar',
'description' => 'Widgets in this area will be shown in the sidebar.',
'before_widget' => '<div class="sidebar-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'name' => 'First Footer Area',
'description' => 'Widgets in this area will be shown in the footer - left side.',
'before_widget' => '<div class="footer-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'name' => 'Second Footer Area',
'description' => 'Widgets in this area will be shown in the footer - middle left.',
'before_widget' => '<div class="footer-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'name' => 'Third Footer Area',
'description' => 'Widgets in this area will be shown in the footer - middle right.',
'before_widget' => '<div class="footer-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'name' => 'Fourth Footer Area',
'description' => 'Widgets in this area will be shown in the footer - right side.',
'before_widget' => '<div class="footer-box">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));

add_action( 'init', 'create_post_types' );
function create_post_types() {
// Define Post Type For Homepage Highlights
  register_post_type( 'highlights',
    array(
      'labels' => array(
		'name' => _x( 'HP Highlights', 'post type general name' ), // Tip: _x('') is used for localization
		'singular_name' => _x( 'Homepage Highlight', 'post type singular name' ),
		'add_new' => _x( 'Add New', 'Homepage Highlight' ),
		'add_new_item' => __( 'Add New Homepage Highlight' ),
		'edit_item' => __( 'Edit Homepage Highlight' ),
		'new_item' => __( 'New Homepage Highlight' ),
		'view_item' => __( 'View Homepage Highlight' ),
		'search_items' => __( 'Search Homepage Highlights' ),
		'not_found' =>  __( 'No Homepage Highlights found' ),
		'not_found_in_trash' => __( 'No Homepage Highlights found in Trash' ),
		'parent_item_colon' => ''
      ),
      'public' => true,
	  'exclude_from_search' => true,
	  'supports' => array('title','thumbnail','editor'),
	  'menu_icon' => get_stylesheet_directory_uri() . '/images/admin/highlights.png',
    )
  );
// Define Post Type For Slider
  register_post_type( 'slides',
    array(
      'labels' => array(
		'name' => _x( 'Slides', 'post type general name' ), // Tip: _x('') is used for localization
		'singular_name' => _x( 'Slide', 'post type singular name' ),
		'add_new' => _x( 'Add New', 'Slide' ),
		'add_new_item' => __( 'Add New Slide' ),
		'edit_item' => __( 'Edit Slide' ),
		'new_item' => __( 'New Slide' ),
		'view_item' => __( 'View Slide' ),
		'search_items' => __( 'Search Slides' ),
		'not_found' =>  __( 'No Slides found' ),
		'not_found_in_trash' => __( 'No Slides found in Trash' ),
		'parent_item_colon' => ''
      ),
      'public' => true,
	  'exclude_from_search' => true,
	  'supports' => array('title','thumbnail'),
	  'menu_icon' => get_stylesheet_directory_uri() . '/images/admin/slides.png',
    )
  );
// Define Post Type For Prices
  register_post_type( 'pricing',
    array(
      'labels' => array(
		'name' => _x( 'Pricing', 'post type general name' ), // Tip: _x('') is used for localization
		'singular_name' => _x( 'Price Plan', 'post type singular name' ),
		'add_new' => _x( 'Add New', 'Price Plan' ),
		'add_new_item' => __( 'Add New Price Plan' ),
		'edit_item' => __( 'Edit Price Plan' ),
		'new_item' => __( 'New Price Plan' ),
		'view_item' => __( 'View Price Plan' ),
		'search_items' => __( 'Search Price Plans' ),
		'not_found' =>  __( 'No Price Plans found' ),
		'not_found_in_trash' => __( 'No Price Plans found in Trash' ),
		'parent_item_colon' => ''
      ),
      'public' => true,
	  'exclude_from_search' => true,
	  'supports' => array('title', 'editor'),
	  'menu_icon' => get_stylesheet_directory_uri() . '/images/admin/pricing.png',
    )
  );
// Define Post Type For Testimonials
register_post_type( 'Testimonials',
    array(
      'labels' => array(
        'name' => __( 'Testimonials' ),
        'singular_name' => __( 'Testimonial' ),		
		'add_new' => _x( 'Add New', 'Testimonial' ),
		'add_new_item' => __( 'Add New Testimonial' ),
		'edit_item' => __( 'Edit Testimonial' ),
		'new_item' => __( 'New Testimonial' ),
		'view_item' => __( 'View Testimonial' ),
		'search_items' => __( 'Search Testimonials' ),
		'not_found' =>  __( 'No Testimonials found' ),
		'not_found_in_trash' => __( 'No Testimonials found in Trash' ),
		'parent_item_colon' => ''
      ),
      'public' => true,
	  'exclude_from_search' => true,
	  'supports' => array('title','editor','thumbnail'),
	  'menu_icon' => get_stylesheet_directory_uri() . '/images/admin/testimonials.png',
	  'query_var' => true,
	  'rewrite' => array( 'slug' => 'testimonials' ),
    )
  );
// Define Post Type For Services
register_post_type( 'Services',
    array(
      'labels' => array(
        'name' => __( 'Services' ),
        'singular_name' => __( 'Service' ),		
		'add_new' => _x( 'Add New', 'Service' ),
		'add_new_item' => __( 'Add New Service' ),
		'edit_item' => __( 'Edit Service' ),
		'new_item' => __( 'New Service' ),
		'view_item' => __( 'View Service' ),
		'search_items' => __( 'Search Services' ),
		'not_found' =>  __( 'No Services found' ),
		'not_found_in_trash' => __( 'No Services found in Trash' ),
		'parent_item_colon' => ''
		
      ),
      'public' => true,
	  'exclude_from_search' => true,
	  'supports' => array('title','editor','thumbnail'),
	  'menu_icon' => get_stylesheet_directory_uri() . '/images/admin/services.png',
	  'query_var' => true,
	  'rewrite' => array( 'slug' => 'services' ),
    )
  );

// Define Post Type For Portfolio
register_post_type( 'Portfolio',
    array(
      'labels' => array(
        'name' => __( 'Portfolio' ),
        'singular_name' => __( 'Portfolio' ),		
		'add_new' => _x( 'Add New', 'Portfolio Project' ),
		'add_new_item' => __( 'Add New Portfolio Project' ),
		'edit_item' => __( 'Edit Portfolio Project' ),
		'new_item' => __( 'New Portfolio Project' ),
		'view_item' => __( 'View Portfolio Project' ),
		'search_items' => __( 'Search Portfolio Projects' ),
		'not_found' =>  __( 'No Portfolio Projects found' ),
		'not_found_in_trash' => __( 'No Portfolio Projects found in Trash' ),
		'parent_item_colon' => ''
		
      ),
      'public' => true,
	  'supports' => array('title','editor','thumbnail', 'comments' ),
	  'menu_icon' => get_stylesheet_directory_uri() . '/images/admin/portfolio.png',
	  'query_var' => true,
	  'rewrite' => array( 'slug' => 'portfolio' ),
    )
  );
}

//Create project taxonomies
add_action( 'init', 'create_taxonomies' );
function create_taxonomies() {
	$cat_labels = array(
		'name' => __( 'Categories' ),
		'singular_name' => __( 'Category' ),
		'search_items' =>  __( 'Search Categories' ),
		'all_items' => __( 'All Categories' ),
		'parent_item' => __( 'Parent Category' ),
		'parent_item_colon' => __( 'Parent Category:' ),
		'edit_item' => __( 'Edit Category' ),
		'update_item' => __( 'Update Category' ),
		'add_new_item' => __( 'Add New Category' ),
		'new_item_name' => __( 'New Category Name' ),
		'choose_from_most_used'	=> __( 'Choose from the most used categories' )
	); 	

	register_taxonomy('portfolio_cats','portfolio',array(
		'hierarchical' => true,
		'labels' => $cat_labels,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'portfolio-category' ),
	));	
	
	$tag_labels = array(
		'name' => __( 'Tags' ),
		'singular_name' => __( 'Tag' ),
		'search_items' =>  __( 'Search Tags' ),
		'all_items' => __( 'All Tags' ),
		'parent_item' => __( 'Parent Tag' ),
		'parent_item_colon' => __( 'Parent Tag:' ),
		'edit_item' => __( 'Edit Tag' ),
		'update_item' => __( 'Update Tag' ),
		'add_new_item' => __( 'Add New Tag' ),
		'new_item_name' => __( 'New Tag Name' )
	); 	

	register_taxonomy('portfolio_tags','portfolio',array(
		'hierarchical' => false,
		'labels' => $tag_labels,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'portfolio-tag' ),
	));
	
}

// functions run on activation --> important flush to clear rewrites
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
	$wp_rewrite->flush_rules();
}
?>